package com.ruoyi.web.controller.CollectController;

import com.ruoyi.system.domain.vo.Focus;
import com.ruoyi.system.domain.vo.Results;
import com.ruoyi.system.service.FocusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.web.controller.common.R;

import java.util.List;

@RestController
@RequestMapping("/api")
public class FocusController {
    @Autowired
    private FocusService focusService;
    @PostMapping("/addfocus")
    public R<String> addfocus(@RequestBody Focus focus)
   {
       focusService.addfocus(focus);
       return R.success(1,"添加成功");
   }
    @PostMapping("/deletefocus")
  public R<String> deletefcous(@RequestBody Focus focus)
  {
      focusService.delectfocus(focus);
      return R.success(1,"添加成功");

  }
  @PostMapping("/selectfocus/ByUserid")
    public  R<List<Focus>> select(@RequestBody Focus focus)
  {
      List<Focus> select = focusService.selecr(focus);
      for(Focus f:select)
      {
          List<Focus> foci = focusService.selectSkillname(f.getFocusid());
          String s = null;
          for(Focus focuss : foci){
              s=s+focuss.getSkillname()+"  ";
          }
          f.setSkillname(s);
      }
      return R.success(select.size(),select);
  }
    @PostMapping("/selectfocus/Byfocusid")
    public  R<List<Focus>> selectByFocus(@RequestBody Focus focus)
    {
        List<Focus> select = focusService.selectByFocusid(focus);
        for(Focus f:select)
        {
            List<Focus> foci = focusService.selectSkillname(f.getFocusid());
            String s = "";
            for(Focus focuss : foci){
                s=s+focuss.getSkillname()+"  ";
            }
            f.setSkillname(s);
        }
        return R.success(select.size(),select);
    }
    @GetMapping("/selectBy/{userid}/{focusid}")
    public Results get(@PathVariable("userid") Long userid ,@PathVariable("focusid") Long focusid){
        Focus foci = null;
        foci = focusService.selectById(userid, focusid);
        if(foci==null){
            return new Results(404,"没查到",null);
        }
        List<Focus> focis = focusService.selectSkillname(foci.getFocusid());
        String s = null;
        for(Focus focuss : focis){
            s=s+focuss.getSkillname()+"  ";
        }
        foci.setSkillname(s);
        return new Results(400,"查到了",foci);
    }

}
